#include "ContentScreen.h"
#include "EndScreen.h"
#include "PuzzleContent.h"
#include "StreamContent.h"
#include "HackContent.h"
#include "FinalContent.h"
#include <MultiWidgets\TextWidget.hpp>

void ContentScreen::nextScreen(){
	Radiant::BinaryData data;
	//data.write(temp);
	eventSend("nextScreen",data);
}

void ContentScreen::init(){

	


	videoStream = MultiWidgets::create<HomeStream>() ;
	videoStream->setBackgroundColor(1,1,1,1);
	videoStream->setSize(width()/4, height()/4);
	videoStream->setInputFlags(INPUT_NONE);
	addChild(videoStream);



	leftBar = MultiWidgets::create<Menu>();
	leftBar->setBackgroundColor(1,1,1,0.2);
	leftBar->setSize(width()/4, height()*3/4);
	leftBar->setLocation(0,videoStream->height());
	leftBar->setFixed();
	leftBar->setBorderWidth(5);
	leftBar->setBorderColor(1,1,1,1);
	addChild(leftBar);



	content = MultiWidgets::create<PuzzleContent>();
	content->eventAddListener("nextContent", "nextStart", this);
	content->setSize(width()*3/4, height());
	content->setFixed();
	content->setLocation(width()/4,0);
	content->setBackgroundColor(1,1,1,0.1);
	content->init();
	addChild(content);



	auto b1 = MultiWidgets::create<MultiWidgets::TextWidget>("end");
	b1->setInputFlags(INPUT_SINGLE_TAPS);
	b1->setLocation(width()-100,0);
    b1->eventAddListener("single-tap", "nextScreen", this);
	addChild(b1);

}

void ContentScreen::nextContent(const QByteArray & messageId){
	removeChild(content);

	if(messageId == "nextStream"){
		content = MultiWidgets::create<HackContent>();
		content->eventAddListener("nextContent", "nextHack", this);
	} else if ( messageId == "nextHack"){
		content = MultiWidgets::create<FinalContent>();
		content->eventAddListener("nextContent", "nextFinal", this);
	} else if (messageId == "nextStart"){
		content = MultiWidgets::create<StreamContent>();
		content->eventAddListener("nextContent", "nextStream", this);
	} else {
		nextScreen();
	}
	content->setSize(width()*3/4, height());
	content->init();
	content->setLocation(width()/4,0);
	content->setBackgroundColor(1,1,1,0.1);
	addChild(content);



}

 void ContentScreen::eventProcess(const QByteArray & messageId, Radiant::BinaryData & data)
  {
    if(messageId == "nextScreen") nextScreen();
	else if(messageId == "nextStream" || messageId == "nextHack" || messageId == "nextFinal" || messageId == "nextStart"){
		nextContent(messageId);
	}

  }